package xxy.com.customview.view;

import android.content.Context;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;

import xxy.com.customview.R;

/**
 * Created by Administrator on 2017/12/25.
 */

public class MoveWithHeadBehavior extends CoordinatorLayout.Behavior {
    private int lastBottom = -1;
    public MoveWithHeadBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        return dependency.getId() == R.id.main6_view_one;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        if (lastBottom == -1) {
            lastBottom = dependency.getBottom();
        }
        if (dependency.getBottom() != lastBottom) {
            int distance = dependency.getBottom() - lastBottom;
            lastBottom = dependency.getBottom();
            child.offsetTopAndBottom(-distance);
        }
        return true;
    }
}
